package com.mdd.admin.controller.customer;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICustomerDetailService;
import com.mdd.admin.service.ICustomerMianService;
import com.mdd.admin.validate.ClientCrmProjetDetailSearchValidate;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.customer.CustomerMianCreateValidate;
import com.mdd.admin.validate.customer.CustomerMianMatchingSearchValidate;
import com.mdd.admin.validate.customer.CustomerMianUpdateValidate;
import com.mdd.admin.validate.customer.CustomerMianSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.customer.CustomerMianListedVo;
import com.mdd.admin.vo.customer.CustomerMianDetailVo;
import com.mdd.admin.vo.customer.CustomerMianMatchingVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.ClientCrmProjetDetail;
import com.mdd.common.entity.CustomerMian;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/customer")
@Api(tags = "客户主表管理")
public class CustomerMianController {

    @Resource
    ICustomerMianService iCustomerMianService;

    @Resource
    ICustomerDetailService iCustomerDetailService;

    @GetMapping("/list")
    @ApiOperation(value="客户主表列表")
    public AjaxResult<PageResult<CustomerMianListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated CustomerMianSearchValidate searchValidate) {
        PageResult<CustomerMianListedVo> list = iCustomerMianService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/all")
    @ApiOperation(value="客户主表列表")
    public AjaxResult<List<CustomerMianListedVo>> all(@Validated CustomerMianSearchValidate searchValidate) {
        List<CustomerMianListedVo> list = iCustomerMianService.all(searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="客户主表详情")
    public AjaxResult<CustomerMianDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CustomerMianDetailVo detail = iCustomerMianService.detail(id);
        detail.setDetailVo(iCustomerDetailService.detailByMianId(detail.getId()));
        return AjaxResult.success(detail);
    }

    @Log(title = "客户主表新增")
    @PostMapping("/add")
    @ApiOperation(value="客户主表新增")
    public AjaxResult<Object> add(@Validated @RequestBody CustomerMianCreateValidate createValidate) {
        CustomerMian customerMian = iCustomerMianService.add(createValidate);
        return AjaxResult.success(customerMian);
    }

    @Log(title = "客户主表编辑")
    @PostMapping("/edit")
    @ApiOperation(value="客户主表编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CustomerMianUpdateValidate updateValidate) {
        iCustomerMianService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户主表删除")
    @PostMapping("/del")
    @ApiOperation(value="客户主表删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iCustomerMianService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @Log(title = "项目政策信息匹配公司")
    @PostMapping("/matching")
    @ApiOperation(value="项目基本信息匹配公司")
    public AjaxResult<List<CustomerMianMatchingVo>> matching(@Validated @RequestBody CustomerMianMatchingSearchValidate searchValidate) {
        return  AjaxResult.success(iCustomerMianService.matching(searchValidate));
    }
}
